﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;

using CloudSoft.Workflows;

namespace ERPStore.NewsLetters.Workflows.Activities
{
	public sealed class SavePendingRequestList : CodeActivity
	{
		public InArgument<Models.Campaign> Campaign { get; set; }
		public InArgument<List<Models.PendingItem>> PendingRequestList { get; set; }

		protected override void Execute(CodeActivityContext context)
		{
			var campaign = context.GetValue(this.Campaign);
			var pendingRequestList = context.GetValue(this.PendingRequestList);
			var newsLettersService = context.GetService<Services.NewsLettersService>();

			context.ReportProgress("Filtrage de la liste terminé");
			foreach (var item in pendingRequestList)
			{
				newsLettersService.SavePendingItem(item);
			}
			context.ReportProgress(string.Format("{0} emails après filtre au départ", PendingRequestList));
			newsLettersService.SaveCampaign(campaign);
		}
	}
}
